#ifndef XXMANAGER_H
#define XXMANAGER_H

#include <QMutex>
#include <QMap>
#include <QString>
#include <QMutexLocker>
#include <QSharedPointer>

template<class T>
class XXmanager{
public:
    XXmanager(){}
    virtual ~XXmanager(){}

    bool exists(const QString &name){
        return _nameToObj.contains(name);
    }
    bool add(const QString &name, QSharedPointer<T> t){
        QMutexLocker locker(&_mutex);
        if(_nameToObj.contains(name)){
            return false;
        }
        _nameToObj.insert(name,t);
        return true;
    }
    QSharedPointer<T> take(const QString &name){
        QMutexLocker locker(&_mutex);
        return _nameToObj.take(name);
    }
    void remove(const QString &name){
        QMutexLocker locker(&_mutex);
        _nameToObj.remove(name);
    }

private:
    QMutex _mutex;
    QMap<QString,QSharedPointer<T>> _nameToObj;
};

#endif
